<?php
function removeBlanksInArray ($arr) {
	foreach($arr as $key => $value) {
		if(!empty($value))
			$newArr[$key] = $value;
	}
	return $newArr;
}
define('PAGE_LOAD_START',round(microtime(), 4));
$system_content = "";
$system_header = "";
function windowsToUnixPathC ($str) {
	$str = preg_replace('/[a-zA-Z]:\\\/', '\\', $str);
	$str = str_replace("\\",'/', $str);
	return $str;
}
$base_pages = array("index.php", "admin.php", "test.php", "config.php", __FILE__,"includes/admin/editors/fckeditor/editor/plugins/lemurcmslinks/");
$base_url[0] = windowsToUnixPathC(realpath(getcwd().'/')).'/';
foreach($base_pages as $key => $value) {
	$base_url = explode($value, $base_url[0]);
}
$base_url = explode("includes/admin/tinybrowser/", $base_url[0]);
$base_url[0] = rtrim($base_url[0], '/').'/';

$visual[0] = $_SERVER["REQUEST_URI"];
foreach($base_pages as $key => $value) {
	$visual = explode($value, $visual[0]);
}
if(SIMPLE_CLEAN_URLS) {
	$visual[0] = rtrim($visual[0], '/');
	$visual = preg_split(SIMPLE_CLEAN_URLS_REGEX, $visual[0]);
/*	
	$ex = explode('/', $visual[0]);
	$count = count($ex);
	if(substr_count($visual[0], '/') == 0) {
		$visual[0] = '/';
	}
	else {
		$diff = array_diff(explode('/',rtrim($base_url[0], '/')), $ex);
		if(empty($diff))
			$dir = is_dir('/'.ltrim($visual[0],'/'));
		else
			$dir = is_dir($base_url[0].$visual[0]);
		if($dir) {
			for($i = 0;$i < $count;$i++) {
				if(empty($ex[$i]))
					$final = '';
				else
					$final .= $ex[$i].'/';
			}
		}
		else {
			for($i = 0;$i < ($count - 1);$i++) {
				if(empty($ex[$i]))
					$final = '';
				else
					$final .= $ex[$i].'/';
			}
		}
	}
	$visual[0] = '/'.$final;*/
}
elseif(substr_count($visual[0],CONTENT_SLUG.'=') > 0) {
	$visList = explode('/', $visual[0]);
	array_pop($visList);
	$visual[0] = rtrim(implode('/', $visList), '/').'/';
}
else {	
	$visual = preg_split(CLEAN_URL_REGEX, $visual[0]);
}
$visual = explode("search/", $visual[0]);
if(substr_count($visual[0], '?') > 0) {
	$visual = explode('?debug=true', $visual[0]);
}
$visual[0] = rtrim($visual[0], '/').'/';
define('BASE_URL', $base_url[0]);
define('SERVER_ABS_PATH', $base_url[0]);
define('SERVER_ABS_URL', $base_url[0]);
define('THEME_URL', $visual[0]);
define('VISUAL_PATH', $visual[0]);
define('VISUAL_URL', $visual[0]);
if(!defined('S_BASE_URL')) {
	define('S_BASE_URL', $visual[0]);
}
?>